var tbl_notreturn = $('#tbl_notreturn');
tbl_notreturn.bootstrapTable({
    url:'borrow/list',
    contentType:'application/x-www-form-urlencoded',
    method:'POST',
    /*toolbar:'#toolbar',*/
    sidePagination:'server',
    pageNumber:1,//当前页
    pageSize:5,//每页条数
    pageList:[5, 10, 15, 20,'ALL'],
    dataType:'json',//返回数据的类型
    detailView:true,
    cache:false,
    pagination:true,//使用分页
    showRefresh:true,//右上角刷新按钮
    showColumns:true,//右上角,列,列表
    /*queryParams:function (params) {
        var name = $('#toolbar>form').find('#customerName').val();
        var address = $('#toolbar>form').find('#customerAddress').val();
        params["name"] = name;
        params["address"] = address;
        return params;
    },*/
    classes:'table table-hover table-striped',
    columns:[{
        checkbox:true
    },{
        field:'num',
        title:'序号',
        align:'center',
        formatter:function(value,row,index){

            return (index+1);
        },
    },{
        field:'customer',
        title:'客户姓名',
        align:'center',
        formatter:function (value,row,index) {
            console.log(row)
            return row.customer.name;
        }
    },{
        field:'book',
        title:'图书名称',
        align:'center',
        formatter:function (value,row,index) {
            return row.book.book_name;
        }
    },{
        field:'borrow_date',
        title:'借书日期',
        align:'center'
    },{
        field:'expect_return_date',
        title:'预计归还日期',
        align:'center'
    },{
        field:'operation',
        title:'操作',
        align:'center',
        formatter:function (value,row,index) {
            var array = [
                '<a href="javascript:void(0)" onclick="returnBook(\'borrow/returnbook?id='+row.borrow_id+'\',\'#tbl_customer\')"><span>还书</span></a>&nbsp;&nbsp;',
                ''
            ];
            return array.join('');
        }
    }]
});

function returnBook(url,bootstraptable) {
    $.ajax({
        'type':'post',
        'url':url,
        'dataType':'json',//返回值类型
        'success':function (d) {//result代表Controller返回值
            if (d.result) {
                swal("操作成功！", "数据操作成功,表格已经自动刷新", "success");
                $(bootstraptable).bootstrapTable('refresh');
                $('#myModal').modal('hide');
            }
        }
    });
}

function borrow(title,url){
    $('#uploadModal').find('.modal-title').empty().text(title);
    $('#uploadModal').find('.modal-body').empty().load(url);
    $('#uploadModal').modal('show');
}

//批量导出
function exportExcel(url){
    var form = document.createElement("form");
    form.setAttribute("action", url);
    form.setAttribute("method", "post");
    document.getElementsByTagName("body")[0].appendChild(form);
    form.submit();
}
